package com.platform_server.exception;

import com.platform_server.entity.response.Header;
import com.platform_server.entity.response.QueryResponse;
import com.platform_server.entity.response.ResponseBase;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * 全局异常处理
 *
 * @Author：Kevin.W.Liu
 * @Date: 2022/3/13
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalException {
    //捕捉SQL异常
    @ExceptionHandler(SQLException.class)
    public ResponseBase RTSqlException(SQLException e){
        QueryResponse<String> response = new QueryResponse<>();
        Header header = new Header(500,"数据库异常，操作失败");
        response.setHeader(header);
        return response;
    }
}
